$(function() {
	$(".hd").on(
			"click",
			".btn",
			function(e) {
				var target = $(this);
				// 获取优惠券id
				var id = target.attr("id");
				// 获取优惠券数量
				var num = target.attr("num");
				// 获取优惠券名称
				var name = target.attr("dname");
				// 获取优惠券有效时间
				var time = target.attr("dtime");
				if (target.text() == "领优惠券") {
					$.ajax({
						url : "ddiscount",
						data : {
							id : id,
							num : num,
							name : name,
							time : time
						},
						complete : function(xhr, status) {
							var sessionStatus = xhr
									.getResponseHeader("sessionstatus");
							if (sessionStatus == "timeout") {
								layer.alert("操作失效,您需要登录！");
								window.location.replace(xhr
										.getResponseHeader("loginpath"));
							} else {
								target.text("已领取").css("background", "gray");
							}
						}
					});
				}

			});

});